#!/usr/bin/env python3
"""
启动 Web 前端 + API 服务

运行本脚本即可启动 FastAPI（挂载前端静态资源）。
"""

import os
import sys
import uvicorn

# 添加src目录到Python路径
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "src"))


def print_banner(host: str, port: int):
    banner = f"""
\033[38;5;33m███████╗██╗███╗   ███╗██████╗ ██╗     ███████╗██████╗  █████╗  ██████╗\033[0m
\033[38;5;39m██╔════╝██║████╗ ████║██╔══██╗██║     ██╔════╝██╔══██╗██╔══██╗██╔═══██╗\033[0m
\033[38;5;45m███████╗██║██╔████╔██║██████╔╝██║     █████╗  ██████╔╝███████║██║   ██║\033[0m
\033[38;5;51m╚════██║██║██║╚██╔╝██║██╔═══╝ ██║     ██╔══╝  ██╔══██╗██╔══██║██║   ██║\033[0m
\033[38;5;81m███████║██║██║ ╚═╝ ██║██║     ███████╗███████╗██║  ██║██║  ██║╚██████╔╝\033[0m
\033[38;5;123m╚══════╝╚═╝╚═╝     ╚═╝╚═╝     ╚══════╝╚══════╝╚═╝  ╚═╝╚═╝  ╚═╝ ╚═════╝ \033[0m

\033[38;5;39m┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\033[0m
\033[38;5;45m┃  🚀 SimpleRAG Web + API 已启动                         ┃\033[0m
\033[38;5;51m┃  UI:  http://{host}:{port}/ui/                         ┃\033[0m
\033[38;5;81m┃  API: /health /config /upload /rebuild /query          ┃\033[0m
\033[38;5;123m┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\033[0m
"""
    print(banner)


def main():
    host = os.getenv("RAG_HOST", "localhost")
    port = int(os.getenv("RAG_PORT", "8000"))
    print_banner(host, port)
    uvicorn.run("src.server.app:app", host=host, port=port, reload=False)


if __name__ == "__main__":
    main()